package com.bootx.entity;

import com.bootx.common.BaseAttributeConverter;
import com.bootx.pojo.Example;
import com.bootx.pojo.FormItem;
import com.fasterxml.jackson.annotation.JsonView;
import jakarta.persistence.*;
import org.hibernate.validator.constraints.Length;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author black
 */
@Entity
public class WriteTool extends OrderedEntity<Long> {

    @JsonView({ViewView.class,PageView.class})
    private String name;

    @JsonView({PageView.class})
    private String memo;

    @JsonView({PageView.class})
    private String icon;

    private String path;

    @Convert(converter = FormItemConverter.class)
    @Column(columnDefinition = "json")
    @JsonView({ViewView.class,PageView.class})
    private List<FormItem> formItems = new ArrayList<>();

    @ManyToMany(fetch = FetchType.LAZY,cascade = CascadeType.ALL)
    private Set<WriteToolCategory> writeToolCategories = new HashSet<>();

    private Integer type;

    @Convert(converter = ExampleConverter.class)
    @Column(columnDefinition = "json")
    @JsonView({ViewView.class,PageView.class})
    private List<Example>  examples = new ArrayList<>();

    @Length(max = 8000)
    @Column(columnDefinition = "varchar(8000)")
    private String systemPrompt;

    @Length(max = 4000)
    @Column(columnDefinition = "varchar(4000)")
    private String userPrompt;

    @Transient
    @JsonView({ViewView.class,PageView.class})

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMemo() {
        return memo;
    }

    public void setMemo(String memo) {
        this.memo = memo;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public Set<WriteToolCategory> getWriteToolCategories() {
        return writeToolCategories;
    }

    public void setWriteToolCategories(Set<WriteToolCategory> writeToolCategories) {
        this.writeToolCategories = writeToolCategories;
    }

    public List<FormItem> getFormItems() {
        return formItems;
    }

    public void setFormItems(List<FormItem> formItems) {
        this.formItems = formItems;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public List<Example> getExamples() {
        return examples;
    }

    public void setExamples(List<Example> examples) {
        this.examples = examples;
    }

    public String getSystemPrompt() {
        return systemPrompt;
    }

    public void setSystemPrompt(String systemPrompt) {
        this.systemPrompt = systemPrompt;
    }

    public String getUserPrompt() {
        return userPrompt;
    }

    public void setUserPrompt(String userPrompt) {
        this.userPrompt = userPrompt;
    }

    @Convert
    public static class FormItemConverter extends BaseAttributeConverter<List<FormItem>>{

    }

    @Convert
    public static class ExampleConverter extends BaseAttributeConverter<List<Example>>{

    }
}
